<?php
    include_once ("../bussines/ReporteBR.php");
    include_once ("generales.php");
    
    if(isset($_POST["opc"])){
        
        $num_doc = $_POST["num_doc"];
        
        if($_POST["opc"]=="ordenCompra"){
            echo listaOrdenCompra($num_doc);
        }
    }
    
    
    function listaOrdenCompra($num_doc){
            $report = new ReporteBR();
            
            $result = $report->listarOrdenCompra($num_doc);
            
            date_default_timezone_get("America/Lima");
            $fecha = date("d/m/Y - h:i:s A");
            
            $html="<script>function imprimir(){document.getElementById('divImprimir').style.display='none';window.print();document.getElementById('divImprimir').style.display='inline';};";
            $html.="function exportar(){window.open('excel/excelOrdenCompra.php?num_doc=".$num_doc."');};";
            $html.="</script>";
            $html.="<center><table style='font-family:verdana;width:90%;' border='0'>";
            $html.="<tr><td colspan='2' align='left'><img src='images/logo/cl.png' width='100'/></td></tr>";
            $html.="<tr style='font-family:verdana;font-size:15px;'><td colspan='2' align='center'><h1>Orden de Compra</h1></td></tr>";
            $html.="<tr><td width='20%'><b>Nro. Documento :</b></td><td width='90%'>".$num_doc."</td></tr>";
            $html.="<tr><td width='20%'><b>Hasta :</b></td><td width='90%'>".$fecha."</td></tr>";
            $html.="<tr><td colspan='2'><hr></td></tr>";
            $html.="<tr><td colspan='2' align='center'>";
            $html.= "<table border='1' style='font-family:verdana;width:100%;border-collapse: collapse;'  >";
            $html.="<tr style='font-family:verdana;background:#ccc;font-size:12px;height:40px;'>";
            $html.="<th >Item</th>";
            $html.="<th >Producto</th>";
            $html.="<th >Cantidad</th>";
            $html.="<th >Codigo Proveedor</th>";
            $html.="<th >Proveedor</th>";
            $html.="</tr>";
            
            if(sizeof($result)==0){
                $html.="<tr><td colspan=5 align='center'>";
                $html.="No se encontraron registro";
                $html.="</td></tr>";
            }else{
                $count=0;
                foreach ($result as $res){
                    $count++;
                    
                    $html.="<tr style='font-family:verdana;font-size:11px;'>";
                    $html.="<td align='center'>$count</td>";
                    $html.="<td align='center'>$res->producto</td>";
                    $html.="<td align='center'>$res->cantidad</td>";
                    $html.="<td align='center'>$res->cod_proveedor</td>";
                    $html.="<td align='center'>$res->proveedor</td>";
                    $html.="</tr>";
                }
            }
            $html.="</table>";
            $html.="</td></tr>";
            $html.="<tr><td colspan='2'><hr></td></tr>";
            $html.="<tr><td colspan='2' ><b>Numero de Registros : </b>$count</td></tr>";
            $html.="<tr><td colspan='2' align='center'><br><div id='divImprimir'><a href='javascript:imprimir();' id='btnImprimir' title='Imprimir'><img src='images/botones/print.png'/></a>";
            $html.="&nbsp;&nbsp;<a href='javascript:exportar();' id='btnExcel' title='Exportar a Excel'  alt='Exportar a Excel'><img src='images/botones/Excel.png' title='Exportar a Excel' width='30'/></a></div></td></tr>";
            $html.="</table></center>";
            
            return $html;
        }
?>